﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Data.Common;
using Mocola.BLL;
using Mocola.Model;
using Mocola.Common;

namespace Mocola.Net.Web
{
    public partial class left_projects : System.Web.UI.Page
    {
        public string TreesStirng;
        public string TreesScriptsStirng;
        public int RoleId = -1;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RoleId = MocolaUser.CurrentUser.RoleID; // 得到当前用户所属角色ID号

                BindData();
            }
        }

        private void BindData()
        {
            TreesStirng = string.Empty;

            using (IDataReader reader = Databases.MocolaNet.Select(Moc_TreesInfo.Moc_Trees,
                   Moc_TreesInfo.Moc_Trees.UniqueID,
                   Moc_TreesInfo.Moc_Trees.ParentID,
                   Moc_TreesInfo.Moc_Trees.Name,
                   Moc_TreesInfo.Moc_Trees.URL,
                   Moc_TreesInfo.Moc_Trees.Title,
                   Moc_TreesInfo.Moc_Trees.Target,
                   Moc_TreesInfo.Moc_Trees.Icon,
                   Moc_TreesInfo.Moc_Trees.IconOpen,
                   Moc_TreesInfo.Moc_Trees.IsOpen,
                   Moc_TreesInfo.Moc_Trees.Type,
                   Moc_TreesInfo.Moc_Trees.ExtId)
                   .ToDataReader())
            {
                while (reader.Read())
                {
                    int UniqueID = reader.GetInt32(0);
                    int ParentID = reader.GetInt32(1);
                    string Name = reader.GetString(2);
                    string URL = reader.GetString(3);
                    string Title = reader.GetString(4);
                    string Target = reader.GetString(5);
                    string Icon = reader.GetString(6);
                    string IconOpen = reader.GetString(7);
                    string IsOpen = reader.GetString(8);
                    int Type = reader.GetInt32(9);
                    int ExtId = reader.GetInt32(10);

                    TreesStirng += "d.add(" + UniqueID + "," + ParentID + ",'" + Name + "','" + URL + "', '" + Title + "','" + Target + "','" + Icon + "'," + IconOpen + "," + IsOpen + ");\n";

                    TreesScriptsStirng += "op('sd" + UniqueID + "'," + UniqueID + ",'" + Name + "'," + ParentID + "," + ExtId + "," + Type + ");";
                }
                reader.Close();
            }
        }

        private static string GetNullableString(IDataReader reader, int col) {
			if(reader.IsDBNull(col) == false)
				return reader.GetString(col);
			return null;
		}
    }
}
